﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="StockAssignmentViewModel.cs" company="DST Nexdox">
//   Copyright (c) DST Nexdox. All rights reserved.
// </copyright>
// <summary>
//   Defines the StockAssignmentViewModel type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace DocProcessingWorkflow.Models.JobsAdmin
{
  using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using DocProcessingWorkflow.Models.MediaStock;
  using DocProcessingWorkflow.Models.Stock;

  using Entities;

  public class StockAssignmentViewModel
  {
    public StockAssignmentViewModel()
    {
      this.ExistingStock = new List<MediaStockViewModel>();
      this.AvailableStock = new List<StockViewModel>();
    }

    public Int32 MediaDefinitionId { get; set; }

    public String StockType { get; set; }

    public String DisplayStockType { get; set; }

    public String DisplayStockTypeSingular { get; set; }

    public String Filter { get; set; }

    public Boolean AllowEditingStationNumbers { get; set; }

    public List<MediaStockViewModel> ExistingStock { get; set; }

    public List<StockViewModel> AvailableStock { get; set; }

    public void AddExistingStock(IEnumerable<MediaStockEntity> mediaStocks)
    {
      foreach (MediaStockEntity mediaStock in mediaStocks)
      {
        this.ExistingStock.Add(this.ToMediaStockViewModel(mediaStock));
      }
    }

    public void AddAvailableStock(IEnumerable<StockEntity> stocks)
    {
      foreach (StockEntity stock in stocks)
      {
        this.AvailableStock.Add(this.ToStockViewModel(stock));
      }
    }

    private MediaStockViewModel ToMediaStockViewModel(MediaStockEntity mediaStock)
    {
      return new MediaStockViewModel
      {
        MediaStockId = mediaStock.MediaStockId,
        Code = mediaStock.Code,
        Description = mediaStock.Description,
        StationNumber = mediaStock.StationNumber,
        Weight = mediaStock.Weight,
        SizeX = mediaStock.SizeX,
        SizeY = mediaStock.SizeY,
        Facing = mediaStock.Facing,
        Colour = mediaStock.Colour
      };
    }

    private StockViewModel ToStockViewModel(StockEntity stock)
    {
      return new StockViewModel
      {
        StockId = stock.StockId,
        Code = stock.Code,
        Description = stock.Description,
        Weight = stock.Weight,
        SizeX = stock.SizeX,
        SizeY = stock.SizeY,
        Facing = stock.Facing,
        Colour = stock.Colour
      };
    }
  }
}